package com.hst.capacity.infra.persistence.jpa.order.specialcar;

import com.hst.capacity.domain.model.entity.order.specialcar.SpCarOrderSettlementEntity;
import com.hst.capacity.domain.model.response.specialcar.SpSettlementViewVO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

public interface SpOrderSettlementRepository extends JpaRepository<SpCarOrderSettlementEntity, String>, JpaSpecificationExecutor<SpCarOrderSettlementEntity> {

    /**
     * 根据订单ID查找订单结算表信息
     * @param idOrder
     * @return
     */
    SpCarOrderSettlementEntity findByIdOrder(String idOrder);

    @Query("select new com.hst.capacity.domain.model.response.specialcar.SpSettlementViewVO(v,s) from SpCarOrderSettlementEntity s left join SpCarOrderSettlementViewEntity v on s.idOrderSettlement = v.idOrderSettlement where v.idFranchisee=:idFranchisee")
    Page<SpSettlementViewVO> findByIdFranchisee(String idFranchisee, PageRequest pageRequest);

}
